
// 1. boolean 
let bol:boolean = true;
bol = false;

// 2. number
let num:number = 123;

let num1:number;
num1 = 123;
num1 = 456;
num1 = 789;


// 3. string
let str:string = "哈哈";
str = "true";
str = "123";

// 4. object
let obj:object = {a:1,b:2}
obj = {};

// 5. void   ===  undefined   约束函数的返回值类型
let un:void = undefined;
un = undefined;

function demo():void{
   
}

// 6. any  任意类型   【在ts中面向any编程】
let a:any = 1;
a = "123";
a = [];
a = {}
a = true;

// 7. 字面量
let b:"suibian" = "suibian";
b = "suibian";

let c:110;
c = 110;

// 8. array
//  数组:  存储相同数据类型的集合 叫做数据
/* 
let arr = [3.1415926,"我在学习ts"];
arr[0]. */



// toFixed(3)  保留小数点后的几位
let arr:number[] = [3.1415926,12345,67890];
console.log(arr[0].toFixed(1));

let arr1:string[] = ["我要学习ts","再来一句话"];
console.log(arr1[1].slice(0,2));

// 9. 元祖  限制为固定长度与类型的数组
let arr2:[number,string] = [123,"abc"];
console.log(arr2[1].slice(0,1));

// 10. 枚举 enum

enum Gender{
    Male="男",
    Female="女",
    Secret="保密"
}

console.log(Gender);

let person = {
    name:'张三',
    age:18,
    sex:Gender.Secret
}


// 11. 联合类型
let aa:number | string;
aa = "abc";
aa = 123;
// aa = true;  //错误

// 12. 类型推断
let cc = 123;
cc = 456;
// cc = "abc"

let  dd = "abc";
dd = "qwrwe";
// dd = true;

// 13. 类型断言
(async () => {

    let v: number | string;

    v = await new Promise((resolve) => {
      resolve(3.1415926);
    });

    // v.toFixed(3);  // 代码正确的，编译器报错

    // v.slice(0,3)   // 代码错误的，编译器报错

    // console.log((v as number).toFixed(3));

    //方式一  as
    console.log((v as number).toFixed(2));
    //方式二  <类型>   <泛型>
    // console.log((<number>v).toFixed(2));
  })()







// 解决命名冲突
export {};